<template>
  <a-card :bordered='false' class='card-area'>
    <a-divider orientation="left">
      既往史
    </a-divider>
    <a-row justify='start'>
      <a-form-model-item label='主要疾病' :label-col='{span: 2 }' :wrapperCol='{span: 20 }' style='margin-left: 26px'>
        <j-multi-select-tag v-model='model.baseDisease'  dictCode='base_disease' style='min-width: 300px'/>
      </a-form-model-item>
    </a-row>
    <a-row justify='start'>
      <a-form-model-item label='手术名' :label-col='{span: 2 }' :wrapperCol='{span: 20 }'>
        <a-input placeholder='请输入手术名' v-model='model.surgicalName' style='width: 180px' />
        <span style='margin-left: 20px'>手术时间：</span>
        <j-date v-model="model.surgicalTime"  :show-time="false" date-format="YYYY-MM-DD" style='width: 260px'></j-date>
      </a-form-model-item>
    </a-row>
    <a-row justify='start'>
      <a-form-model-item label='外伤名' :label-col='{span: 2 }' :wrapperCol='{span: 20 }'>
        <a-input placeholder='请输入外伤名' v-model='model.traumaName' style='width: 180px' />
        <span style='margin-left: 20px'>外伤时间：</span>
        <j-date v-model="model.traumaTime"  :show-time="false" date-format="YYYY-MM-DD" style='width: 260px'></j-date>
      </a-form-model-item>
    </a-row>
    <a-divider orientation="left">
      家族史
    </a-divider>
    <a-row justify='start'>
      <a-form-model-item label='父亲' :label-col='{span: 2 }' :wrapperCol='{span: 20 }'>
        <j-multi-select-tag v-model='model.fatherFamily'  dictCode='base_disease' style='min-width: 300px'/>
      </a-form-model-item>
    </a-row>
    <a-row justify='start'>
      <a-form-model-item label='母亲' :label-col='{span: 2 }' :wrapperCol='{span: 20 }'>
        <j-multi-select-tag v-model='model.motherFamily'  dictCode='base_disease' style='min-width: 300px'/>
      </a-form-model-item>
    </a-row>
    <a-form-model-item label='遗传病史' :label-col='{span: 2 }' :wrapperCol='{span: 20 }'>
      <a-input placeholder='请输入遗传病史' v-model='model.inheritance' style='width: 560px' />
    </a-form-model-item>
    <a-divider orientation="left">
      药物过敏史
    </a-divider>
    <a-row justify='start'>
      <a-form-model-item label='药物过敏史' :label-col='{span: 2 }' :wrapperCol='{span: 20 }'>
        <a-select v-model='model.drugAllergyList' placeholder='请选择药物过敏史' mode="multiple" style="width: 80%">
          <a-select-option v-for='item in drugAllergyList' :key='item.value' :value='item.value'>{{ item.key }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
    </a-row>
    <a-form style="max-width: 500px; margin: 40px auto 0;">
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
        <a-button :loading="loading" type="primary" @click="onSubmit">提交</a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import { httpAction, putAction, getAction, postAction } from '@/api/manage'

export default {
  name: '客户档案明细-基本信息',
  props: {
     patientId: Number,
  },
  watch: {
    patientId(newValue) {
       this.getPatient(newValue);
    }
  },
  data() {
    return {
      disabled: true,
      model: {

      },
      loading:false,
      layout: {
        labelCol: { span: 8 },
        wrapperCol: { span: 14 }
      },
      labelCol: { style: { width: '110px' } },
      wrapperCol: { style: { width: '610px' } },
      confirmLoading: false,
      validatorRules: {
        realName: [{ required: true, message: '请输入客户姓名!' }],
        cardNo: [{ required: true, message: '请输入身份证!' }],
        sex: [{ required: true, message: '请选择性别!' }],
        mobilePhone: [{ required: true, message: '请输入联系手机号!' }],
        birthday: [{ required: true, message: '请输入生日日期!' }],
        customType: [{ required: true, message: '请输入客户类型!' }],
        weight: [{ required: true, message: '请输入体重!' }],
        height: [{ required: true, message: '请输入身高!' }],
        address: [{ required: true, message: '请输入家庭地址!' }]
      },
      url: {
        get: '/his/patient/base/info/community/',
        getArchives: '/his/patient/archives',
        getDict: '/sys/dict/checkbox',
        save: '/his/patient/base/info/community/save',
      },
      jCustomTypeOptions: [],
      jLiveTypeOptions: [],
      jLikesOptions: [],
      modelArchives: {},
      drugAllergyList:[],
      parentId:0,
    }
  },
  created() {
    let that = this
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    getAction(this.url.getDict + '/speciality_type').then((res) => {
      if (res.success) {
        that.jLikesOptions = res.result
      }
    })
    getAction(this.url.getDict + '/speciality_type').then((res) => {
      if (res.success) {
        that.jLikesOptions = res.result
      }
    })
    getAction(this.url.getDict + '/custom_type').then((res) => {
      if (res.success) {
        that.jCustomTypeOptions = res.result
      }
    })
    getAction(this.url.getDict + '/live_type').then((res) => {
      if (res.success) {
        that.jLiveTypeOptions = res.result
      }
    })
    getAction('/his/case/ai/select/allergyResult').then((res) => {
      if (res.success) {
        that.drugAllergyList = res.result
      }
    })
  },
  methods: {
    getPatient(patientId){
      const that=this;
      that.model.patientId=patientId;
      getAction(this.url.get + '/' + patientId).then((res) => {
        if (res.success) {
          that.model = res.result
        }
      })
    },
    onSubmit() {
      const that=this;
      this.model.nation=this.modelArchives.nation
      this.model.politicsType=this.modelArchives.politicsType
      postAction(this.url.save, this.model).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
        } else {
          that.$message.warning(res.message)
        }
      }).finally(() => {

      })
    },
    handleCancel() {
    }

  }
}
</script>

<style scoped>

</style>